package extensions

import java.awt.image.BufferedImage
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.InputStream
import javax.imageio.ImageIO

fun BufferedImage.toInputStream(): InputStream?{
    return try {
        val output = ByteArrayOutputStream()
        ImageIO.write(this,"png",output)
        val input = ByteArrayInputStream(output.toByteArray())
        output.flush()
        output.close()
        input
    }catch (ex : IOException)
    {
        ex.printStackTrace()
        null
    }
}